﻿using System.Collections;
using System.Collections.Generic;
using UnityEngine;

[System.Serializable]
public class AppConfig
{
    public int alpha = 255;
    public int frameRate = 60;
}

public class AppMgr : MonoSingleton<AppMgr>
{
    public AppConfig appConfig;
    public MainUI mainUI;
    public SpineCreateControl spineCreateControl;
    public WinSetting winSetting;

    protected override void Init()
    {
        base.Init();
        LoadConfig();
        mainUI.Init();
        spineCreateControl = SpineCreateControl.Instance;
        winSetting = WinSetting.Instance;
    }

    private void Update()
    {
        if(Input.GetKeyDown(KeyCode.S))
        {
            SaveConfig();
        }

        if (Input.GetKeyDown(KeyCode.H))
        {
            winSetting.IsPenetrate = mainUI.gameObject.activeSelf;
            //print(winSetting.IsPenetrate);
            if (mainUI.gameObject.activeSelf)
            {
                mainUI.gameObject.SetActive(false);
            }
            else
            {
                mainUI.gameObject.SetActive(true);
            }
        }
    }

    private void LoadConfig()
    {
        appConfig = new AppConfig();
        string configJsonStr = PlayerPrefs.GetString("AppConfig");
        if (string.IsNullOrEmpty(configJsonStr))
        {
            SaveConfig();
        }
        else
        {
            appConfig = JsonUtility.FromJson<AppConfig>(configJsonStr);
        }
    }

    private void SaveConfig()
    {
        string configJsonStr = JsonUtility.ToJson(appConfig);
        PlayerPrefs.SetString("AppConfig", configJsonStr);
    }

}
